<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root">

    </div>
</body>
<script src="../react@17.js"></script>
<script src="../react-dom@17.js"></script>
<script src="../babel.js"></script>
<script type="text/babel">
    class App extends React.Component{
        modelRef = React.createRef();
        render(){
            return (
                <div>
                <button onClick={()=>{
                    console.log(this.modelRef.current)
                    this.modelRef.current.init();
                }}>显示模态框</button>  
                <Model ref={this.modelRef} />  
                </div>
            )
        }
    }

    class Model extends React.Component{
        state={
            isShow:false
        }
        init(){
            this.setState({
                isShow:true
            })
        }
        render(){
            return (
                <div>
                  {
                    this.state.isShow && <div>我是模态框</div>
                  }
                </div>
            )
        }
    }

    ReactDOM.render(<App/>,document.getElementById('root'))
</script>
</html>